<?
 require("sks.inc.php");
 require("sks-status.inc.php");
 header("Content-type: text/plain");
 $servers = unserialize(file_get_contents(dirname(__FILE__)."/sks_cache.serialized"));
 $serverarr = $servers->get_servers();
 
 $status_collection = unserialize(file_get_contents(dirname(__FILE__)."/sks_cache_status_collection.serialized"));
 $servercolarr = $status_collection->get_servers();
 
 shuffle($serverarr);

 $duplicate_check_by_ip = array();
 
 $default_weight = 20;
 $order = array();

 $c = 0;
 
 foreach($serverarr as $server)
 {
  $ip=gethostbyname($server->get_hostname());
 
  if($server->get_ipv6() !== false) 
	$ip6=gethostbyname6($server->get_hostname());
  else
	$ip6="";

  $weight = $server->get_srvweight();
  
  if($servercolarr[$server->get_hostname()]['last_status']==1)
  {
   if(in_array($ip, $duplicate_check_by_ip)) continue; // skip if IP found for record already
   
   $txt["a$c"] .=  "_pgpkey-http._tcp.eu.pool.sks-keyservers.net. SRV 0 $weight 11371 ".$server->get_hostname().".\n";
   $txt["a$c"] .=  "eu.pool A ".$ip."\n";
   //$txt["a$c"] .=  "ipv4.eu.pool A ".$ip."\n";
   if($server->get_ipv6() !== false) 
   {
	$txt["a$c"] .=  "eu.pool AAAA ".$ip6."\n";
	//$txt["a$c"] .=  "ipv6.eu.pool AAAA ".$ip6."\n";
   }
   $order["a$c"] = $weight;
   $duplicate_check_by_ip[] = $ip;

   $c++;
  }
 }
 
 
 asort($order);
 $order_pri = array_reverse($order, true);
 
 $c = 0;
 $max = 10;
 
 foreach($order_pri as $k=>$pri)
 {
  if($c >= $max) continue;
  echo $txt[$k];
  $c++;
 }
?>